<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			let account = JSON.parse(uni.getStorageSync('currentUser')).account
			if(uni.getStorageSync(account+'orderList')){
				let a=JSON.parse(uni.getStorageSync(account+'orderList')).length+''
				uni.setTabBarBadge({
				  index: 1,
				  text: a
				})
			}
			
		// if(uni.getStorageSync('token')){
		// 			uni.switchTab({
		// 				url:'/pages/index/index'
		// 			})
					
		// 		}
		this.$u.get('/users/userinfo').then(res=>{
			if(res.data.code!=-1){
				uni.switchTab({
					url: '/pages/index/index'
				})
				let account=res.data.payload.account
				let a=new Promise((resolve,reject)=>{
					this.$u.post('/table/getTableByaccount',{account:account}).then(res2=>{
					resolve(res2)
				})
				})
				a.then(res3=>{
					console.log(res3,'获取的位置')
					if(res3.data.data==null&&uni.getStorageSync('tablerecords')!=undefined){
						console.log('执行了');
						uni.removeStorageSync('tablerecords')
						uni.removeStorageSync('vuexstate')
						this.CLEAN_TABLE()
					}
				})
			}else{
				uni.showToast({
					title: 'token无效'
				});
				
			}
		})
		},
		methods:{
			...mapMutations(['CLEAN_DISHES', 'CLEAN_TABLE']),
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	/*#ifndef MP*/
	@import url('https://at.alicdn.com/t/font_1681579_yaiyfblc2xt.css');
	/*#endif*/
</style>
